//
//  FirstCellModel.m
//  AffectionBee
//
//  Created by 王炯 on 16/8/20.
//  Copyright © 2016年 chivalrous. All rights reserved.
//

#import "FirstCellModel.h"
#import "NetworkTool.h"


@implementation FirstCellModel


+(instancetype)FirstCellModelWithDict:(NSDictionary *)dict
{
    FirstCellModel *model = [[FirstCellModel alloc] init];
    
    
    [model setValuesForKeysWithDictionary:dict];
    
    
    
    return model;
}

//处理未用到的键值
-(void)setValue:(id)value forUndefinedKey:(NSString *)key
{
    
}

//返回model数据
+(void)GetFirstCellDataArrayWithUrl:(NSString *)urlString andParameter:(NSDictionary *)param Sucess:(void (^)(NSArray<FirstCellModel *> *))successBlock Error:(void (^)())errorBlock
{
    //直接POST请求
    [[NetworkTool sharedManager] oauthLoadDataWithNetworkToolType:NetworkToolTypePOST UrlString:urlString parameters:param SuccessBlock:^(NSDictionary *responseObject) {
        
        
        //(0)取验证码code
        NSNumber *codeNum = responseObject[@"code"];
        
        NSInteger code = [codeNum integerValue];
        
        //(4)返回数组
        if (responseObject[@"data"] && code == 0)
        {
            //(5)取数组
            NSArray *FirstArray = responseObject[@"data"];
            
            //(6)声明一个可变数组
            NSMutableArray *mArray = [NSMutableArray array];
            
            
            //(7)遍历数组，字典转模型
            [FirstArray enumerateObjectsUsingBlock:^(NSDictionary  *obj, NSUInteger idx, BOOL * _Nonnull stop) {
                
                FirstCellModel *model = [FirstCellModel FirstCellModelWithDict:obj];
                
                [mArray addObject:model];
                
            }];
            //(8)返回数据
            if (successBlock)
            {
                successBlock(mArray.copy);
            }
        }
        else
        {
            
            //调用错的block
            if (errorBlock)
            {
                errorBlock();
            }
            
            
        }
        
        
    } failure:^(NSError *error) {
        
        
        //调用错的block
        if (errorBlock)
        {
            errorBlock();
        }
        
        
    }];
}


@end
